package repository

import (
	"context"

	"gitee.com/flycash/simple-im/internal/domain"
	"gitee.com/flycash/simple-im/internal/repository/dao"
)

type ChannelMemberReadRecordRepo interface {
	GetLastReadMsgID(ctx context.Context, uid, channelID int64) (int64, error)
	Save(ctx context.Context, uid int64, record domain.ChannelMsgReadRecord) error
}

type channelMemberReadRecordRepo struct {
	dao dao.UserChannelReadRecordDAO
}

func NewChannelMemberReadRecordRepo(channelDao dao.UserChannelReadRecordDAO) ChannelMemberReadRecordRepo {
	return &channelMemberReadRecordRepo{
		dao: channelDao,
	}
}

func (c *channelMemberReadRecordRepo) GetLastReadMsgID(ctx context.Context, uid, channelID int64) (int64, error) {
	return c.dao.GetLastReadMsgID(ctx, uid, channelID)
}

func (c *channelMemberReadRecordRepo) Save(ctx context.Context, uid int64, record domain.ChannelMsgReadRecord) error {
	return c.dao.Save(ctx, dao.UserChannelReadRecord{
		UID:       uid,
		ChannelID: record.ChannelID,
		LastMsgID: record.LastMsgID,
	})
}
